package cn.zhz.test;

import cn.smbms.pojo.User;
import cn.smbms.service.user.UserService;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class testGetUserList {
    //使用log4j日志记录器
    private static Logger logger = org.apache.log4j.Logger.getLogger(testGetUserList.class);

    @Test
    public void getUserTest() {
//        String[] configs={"applicationContext.xml",
//                "applicationContext-dao.xml",
//                "applicationContext-service.xml"};

        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");


        UserService userService = (UserService) ctx.getBean("userService");

        User userCondition = new User();
        userCondition.setUserName("赵");
        userCondition.setUserRole(3);

        List<User> userList = new ArrayList<User>();
        userList = userService.findUserWithConditions(userCondition);

        for (User userResult : userList) {
            logger.debug("testGetUserList userCode:"
                    + userResult.getUserCode() + " and userName: "
                    + userResult.getUserName() + " and userRole:"
                    + userResult.getUserRole() + " and userRoleName:"
                    + userResult.getUserRoleName() + " and address:"
                    + userResult.getAddress());
        }
        User user = new User();
        user.setUserCode("sas");
        user.setUserName("你好");
        user.setUserPassword("123");
        user.setGender(2);
        try {
            Date time = new SimpleDateFormat("yyyy-MM-dd").parse("2011-12-12");
            user.setBirthday(time);
        } catch (Exception e) {
            e.printStackTrace();
        }
        user.setPhone("123456");
        user.setAddress("郴州");
        user.setUserRole(1);
        user.setCreatedBy(1);
        user.setCreationDate(new Date());
        boolean result = userService.addNewUser(user);
        logger.debug(result);
    }
}